//
//  ActivityView.m
//  ManyCollectionView
//
//  Created by apple on 16/7/13.
//  Copyright © 2016年 apple. All rights reserved.
//
#define WIDTH [[UIScreen mainScreen] bounds].size.width
#define HEIGHT [[UIScreen mainScreen] bounds].size.height

#import "ActivityView.h"
#import "BZBView.h"
#import "BaokuanView.h"
#import "AvtivityTableViewCell.h"
#import "TuijianTableViewCell.h"
#import "ChoseHeaderView.h"

static NSString * JPHeaderId = @"header";
@interface ActivityView ()<UITableViewDelegate,UITableViewDataSource>

@end

@implementation ActivityView
{
    UITableView *activityTV;
}
- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        
        activityTV = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, WIDTH, frame.size.height) style:UITableViewStylePlain];
        
        activityTV.delegate = self;
        activityTV.dataSource = self;
        activityTV.separatorStyle = UITableViewCellSeparatorStyleNone;
        
        [activityTV registerClass:[BZBView class] forCellReuseIdentifier:@"TOPCELL"];
        [activityTV registerClass:[AvtivityTableViewCell class] forCellReuseIdentifier:@"TWOCELL"];
        [activityTV registerClass:[BaokuanView class] forCellReuseIdentifier:@"THREECELL"];
        [activityTV registerClass:[TuijianTableViewCell class] forCellReuseIdentifier:@"FOURCELL"];
        
        //区头
        [activityTV registerClass:[ChoseHeaderView class] forHeaderFooterViewReuseIdentifier:JPHeaderId];
        [self addSubview:activityTV];
    }
    return self;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 0 && indexPath.row == 0) {
        return 120;
    }else if (indexPath.section == 1) {
        return 130;
    }else if (indexPath.section == 2) {
        return 80;
    }else if (indexPath.section == 3) {
        return (WIDTH/2 + 30)* 3;
    }
    return (WIDTH/2 + 30)* 3;;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 5;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (section == 1) {
        return 2;
    }
    return 1;
}


- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 10;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    if (section == 4) {
        return 50;
    }
    return 0.0001;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 0) {
        BZBView *cell = [activityTV dequeueReusableCellWithIdentifier:@"TOPCELL" forIndexPath:indexPath];
        cell.LocalBlock = ^void() {
            if (self.LocalBlock) {
                self.LocalBlock();
            }
        };
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        [cell.localImg setImage:[UIImage imageNamed:@"icon_dz"]];
        cell.localImg.contentMode = UIViewContentModeScaleAspectFit;
        [cell.topImg setImage:[UIImage imageNamed:@"banner_1"]];
        [cell.jiantouImg setImage:[UIImage imageNamed:@"icon_you111"]];
        cell.jiantouImg.contentMode = UIViewContentModeScaleAspectFit;
        cell.titleLB.text = @"万特珠宝";
        cell.localLB.text = @"杭州市文二路";
        return cell;
    }else if (indexPath.section == 1) {
        AvtivityTableViewCell *cell = [activityTV dequeueReusableCellWithIdentifier:@"TWOCELL" forIndexPath:indexPath];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }else if (indexPath.section == 2) {
        BaokuanView *cell = [activityTV dequeueReusableCellWithIdentifier:@"THREECELL" forIndexPath:indexPath];
        [cell.picImg setImage:[UIImage imageNamed:@"banner_2"]];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }else if (indexPath.section == 3) {
    
    
    TuijianTableViewCell *cell = [activityTV dequeueReusableCellWithIdentifier:@"FOURCELL" forIndexPath:indexPath];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
    }else if (indexPath.section == 4) {
        TuijianTableViewCell *cell = [activityTV dequeueReusableCellWithIdentifier:@"FOURCELL" forIndexPath:indexPath];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }
    return nil;
}

#pragma mark ---- 区头
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    if (section == 4) {
        ChoseHeaderView *header = [tableView dequeueReusableHeaderFooterViewWithIdentifier:JPHeaderId];
        return header;
    }
    return nil;
}





@end
